findFoodOrderDetail();

function findFoodOrderDetail() {
    var Request = new Object();
    Request = GetRequest();
    var id = Request['id'];
    var userId = "1";
    var obj = JSON.stringify({
        "id": id,
        "userId": userId,
    });

    httpHelperpost(_API_FOOD_ORDER_DETAIL, obj, function (isSuccess, data) {
        if (isSuccess == true) {
            var response = data.responseText;
            var value = JSON.parse(response);
            var subHtml = "";
            var typeHtml = "";
            var factPrice = value.data.factPrice;

            console.log(response);
            $(".topReturn-text").text(value.data.restaurantName);
            $("#totalPrice").text(factPrice);
            $(".sub-money").text("￥" + factPrice);


            for (var i = 0; i < value.data.foodList.length; i++) {
                subHtml += "<li data-foodId=" + value.data.foodList[i].id + ">"
                    + "<div class='sub-root'>"
                    + "<div class='sub-root-img'><img src=" + value.data.foodList[i].picture + "></div>"
                    + "<div class='sub-root-bar'>"
                    + "<div class='sub-root-title'>" + value.data.foodList[i].name + "</div>"
                    + "<div class='sub-root-type'><span class='sub-root-w'>周一至周日</span><span>免预约</span></div>"
                    + "<div class='sub-root-size'><span>随时退</span><span>过期自动退</span></div>"
                    + "</div>"
                    + "<div class='sub-root-money'>￥<span class='price'>" + value.data.foodList[i].price + "</span></div>"
                    + "</div>"
                    + "<div class='sub-num pd'>"
                    + "<span class='sub-title'>数量</span>"
                    + "<span class='foodNum'>" + value.data.foodList[i].buyNum + "</span>"
                    + "</div>"
                    + "</li>";
            }
            $("#subUl").html(subHtml);

            $("#restaurantDispatch").text(value.data.dispatchName);
            if (value.data.dispatchId == 1) {
                typeHtml = "<div class='sub-realMoney pd'>"
                    + "<span class='sub-title'>实付金额</span><span class='sub-money'>￥" + factPrice + "</span>"
                    + "</div>"
                    + "<div class='sub-phone pd'>"
                    + "<span class='sub-title'>手机号</span>"
                    + "<input class='sub-phone-num' type='text' value=" + value.data.userPhone + " readonly='readonly'>"
                    + "</div>";
            } else if (value.data.dispatchId == 2) {
                typeHtml = "<div class='sub-realMoney pd'>"
                    + "<span class='sub-title'>配送费</span><span class='sub-money'>￥<span id='dispatchPrice'>"+value.data.dispatchPrice+"</span></span>"
                    + "</div>"
                    + "<div class='sub-realMoney pd'>"
                    + "<span class='sub-title'>实付金额</span><span class='sub-money'>￥" + factPrice + "</span>"
                    + "</div>"
                    + "<div class='sub-vouchers pd'>"
                    + "<span class='sub-title'>选择地址</span><div class='sub-select'><span>" + value.data.userAddressInfo.address + "</span><img src='./img/return_01.png'></div>"
                    + "</div>";
            } else if (value.data.dispatchId == 3) {
                typeHtml = "<div class='sub-realMoney pd'>"
                    + "<span class='sub-title'>实付金额</span><span class='sub-money'>￥" + factPrice + "</span>"
                    + "</div>"
                    + "<div class='sub-phone pd'>"
                    + "<span class='sub-title'>手机号</span>"
                    + "<input class='sub-phone-num' type='text' value=" + value.data.userPhone + " readonly='readonly'>"
                    + "</div>";
            }

            $("#subInfor").html(typeHtml);

            if (value.code == 0) {
                console.log("查询成功");

            } else if (value.code == 401) {
                alert(value.message);
                window.location.href = './index.html';
            } else {
                alert(value.message);
                console.log("查询失败");
            }
        } else {
        }
    });
}

//获取url中"?"符后的字串
function GetRequest() {
    var url = location.search; //获取url中"?"符后的字串

    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);

        strs = str.split("&");

        for (var i = 0; i < strs.length; i++) {

            theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
        }
    }
    return theRequest;
}